﻿using TestingConcurrencyBenchmark.Helpers;
using TestingConcurrencyBenchmark.Problems.DiningPhilosophers.Philosophers;

namespace TestingConcurrencyBenchmark.Problems.DiningPhilosophers.DiningPhilosophersSolutions
{
    public class DiningPhilosophersWithEvenNumberMultiplex : AbstractDiningPhilosophers
    {
        private readonly BenchmarkSemaphore _evenNumberMultiplex;

        public DiningPhilosophersWithEvenNumberMultiplex(int nbPhilosophers) : base(nbPhilosophers)
        {
            _evenNumberMultiplex = new BenchmarkSemaphore(nbPhilosophers - 1);
        }

        protected override AbstractPhilosopher CreatePhilosopher(BenchmarkSemaphore leftFork, BenchmarkSemaphore rightFork)
        {
            return new EvenNumberMultiplexPhilosopher(leftFork, rightFork, _evenNumberMultiplex);
        }
    }
}